/** \file OnBalanceVolume_t.cc 
 * Test definitions for the OnBalanceVolume function
 *
 * (C) Copyright by Semih Cemiloglu
 * All rights reserved, see COPYRIGHT file for details.
 *
 * $Id: OnBalanceVolume_t.cc 110 2006-06-19 03:38:33Z semihc $
 *
 *
 */


#include "OnBalanceVolume.hpp"
#include <vector>
#include <list>
#include "Stock.hpp"
#include "SecurityAdaptor.hpp"
#include "TestHarness.hh"

using namespace std;
using namespace TC;


namespace {

  const unsigned DataSize = 54;

  const double data_cls[DataSize] = {
    20.5625, 20.3750, 20.0625, 19.5000, 19.8125, 19.8125, 20.0625,
    20.0625, 20.3750, 20.7500, 20.7500, 20.5625, 20.4375, 20.5625,
    20.5000, 20.5000, 20.8750, 21.1875, 20.9375, 20.9375, 21.1250,
    20.8750, 20.7500, 20.7500, 20.2500, 20.1875, 19.6875, 19.8750,
    20.3125, 19.7500, 19.7500, 20.1875, 20.0000, 20.0000, 19.8750,
    20.1250, 20.1875, 19.8125, 19.9375, 19.6250, 20.2500, 20.5000,
    20.4375, 20.6875, 21.2500, 21.0625, 21.0625, 21.0000, 20.3125, 
    20.3125, 20.4375, 20.5000, 20.7500, 21.0000 };

  const long data_vol[DataSize] = {
    27802, 16178, 22766, 46074, 22904, 20428, 29260, 30652, 38332,
    40054, 19104, 22490, 24626, 24196, 22492, 21374, 27592, 19644,
    21122, 20500, 17398, 23756, 21486, 21784, 34166, 22222, 31060, 
    23002, 27806, 21854, 38410, 40096, 29930, 24606, 24266, 18934,
    27328, 22424, 24486, 23236, 31506, 35564, 17844, 31096, 27380,
    20418, 20386, 23458, 31622, 17112, 18466, 20834, 18082, 37572 };

  const long data_expect[DataSize] = {
    0, -16178, -38944, -85018, -62114, -62114, -32854, -32854,
    5478, 45532, 45532, 23042, -1584, 22612, 120, 120, 27712,
    47356, 26234, 26234, 43632, 19876, -1610, -1610, -35776,
    -57998, -89058, -66056, -38250, -60104, -60104, -20008, -49938,
    -49938, -74204, -55270, -27942, -50366, -25880, -49116, -17610,
    17954, 110, 31206, 58586, 38168, 38168, 14710, -16912, -16912,
    1554, 22388, 40470, 78042 };



}


TEST(OnBalanceVolumeTest, Base)
{
     StockDef s;
     list<StockDef> stocks;
     vector<double> result;
     
     for(unsigned i=0; i<DataSize; ++i) {
       s.setCls(static_cast<StockDef::Price_t>(data_cls[i]));
       s.setVol(static_cast<StockDef::Volume_t>(data_vol[i]));
       stocks.push_back(s);
     }

     OnBalanceVolume(stocks.begin(), stocks.end(), 
		     back_inserter(result),
		     SecurityAdaptor<StockDef>());
     TC_TEST(result.size()==DataSize);
     PrintElements(result, "OnBalanceVolume");

     for(unsigned i=0; i<DataSize; ++i)
       TC_TEST(data_expect[i]==result[i]);


}

  



